import type {
  ParamsConfig,
  articleData,
  rowsData,
  RecommendRows,
  LikeConfig,
  DepResponseInfo,
  Picture,
  FeeConfig,
  FeeResult,
  PartialConsultInfo,
  EvaluteDocConfig,
  ConsultRecord,
  recordList
} from '@/types/consult'
import { request } from '@/utils/request'

// 获取首页文章列表
const getArticleListAPI = (paramsConfig: ParamsConfig) => {
  return request<articleData<rowsData>>(
    'patient/home/knowledge',
    'GET',
    paramsConfig
  )
}
// 推荐关注的医生列表
const getRecommendList = (paramsConfig: ParamsConfig) => {
  return request<articleData<RecommendRows>>(
    'home/page/doc',
    'GET',
    paramsConfig
  )
}
// 关注医生
const likeDoctor = (paramsConfig: LikeConfig) => {
  return request('like', 'POST', paramsConfig)
}
// 获取所有科室
const getAllDep = () => request<DepResponseInfo[]>('dep/all')
// 上传图片
const uploadImageAPI = (file: File) => {
  // 上传文件图片需要包在FormData中
  const fd = new FormData()
  fd.append('file', file)
  console.log(fd)

  return request<Picture>('/upload', 'POST', fd)
}
// 获取就诊信息和抵扣信息 --- 支付页面
const getPriceAPI = (paramsConfig: FeeConfig) => {
  return request<FeeResult>('patient/consult/order/pre', 'GET', paramsConfig)
}
// 生成订单
const getOrderIdAPI = (config: PartialConsultInfo) => {
  return request<{ id: string }>('patient/consult/order', 'POST', config)
}
// 获取支付接口
const getPayAPI = (config: {
  paymentMethod: 0 | 1
  orderId: string
  payCallback: string
}) => {
  return request<{ payUrl: string }>('patient/consult/pay', 'POST', config)
}
// 获取订单详情
const getOrderDetail = (orderId: string) => {
  return request<recordList>('patient/consult/order/detail', 'GET', {
    orderId
  })
}
// 获取处方单
const getPrescriptionUrl = (id: string) => {
  return request<{ url: string }>(`patient/consult/prescription/${id}`)
}
// 评价医生
const evaluteDoctor = (config: EvaluteDocConfig) => {
  return request<{ id: string }>('patient/order/evaluate', 'POST', config)
}
// 获取问诊记录
const getRecordList = (configData: ConsultRecord) => {
  return request<articleData<recordList>>(
    'patient/consult/order/list',
    'GET',
    configData
  )
}
// 删除订单
const delOrder = (id: string) => {
  return request<{ id: string }>(`patient/order/${id}`, 'DELETE')
}
// 取消订单
const cancelOrder = (id: string) => {
  return request(`patient/order/cancel/${id}`, 'PUT')
}

export {
  getArticleListAPI,
  getRecommendList,
  likeDoctor,
  getAllDep,
  uploadImageAPI,
  getPriceAPI,
  getOrderIdAPI,
  getPayAPI,
  getOrderDetail,
  getPrescriptionUrl,
  evaluteDoctor,
  getRecordList,
  delOrder,
  cancelOrder
}
